﻿Imports System.Windows.Forms

Public Class frmOptions

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        saveSettings()
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        If MessageBox.Show("Cancel changes?", "Cancel?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.OK Then
            Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
            Me.Close()
        End If

    End Sub

    Private Sub frmOptions_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'hidecontrols(True, True)
        Button1.BackgroundImage = imgUnit.Images.Item(3)
        Button2.BackgroundImage = imgUnit.Images.Item(2)
        Button3.BackgroundImage = imgUnit.Images.Item(1)
        Button4.BackgroundImage = imgUnit.Images.Item(0)
        Button5.BackgroundImage = imgIcon.Images.Item(0)
        Button6.BackgroundImage = imgIcon.Images.Item(1)
        Button7.BackgroundImage = imgIcon.Images.Item(2)
        Button8.BackgroundImage = imgIcon.Images.Item(3)
        loadSettings()
        updatePreviewFull()
        Me.Refresh()
    End Sub

    Private Sub loadSettings()
        Select Case My.Settings.colorType
            Case 1
                chkclrName.Checked = True
            Case 2
                chkclrSquare.Checked = True
        End Select

        Select Case My.Settings.scoreMode
            Case 1
                chkScoreFixed.Checked = True
            Case 2
                chkScoreIndividual.Checked = True
        End Select

        Select Case My.Settings.matchUp
            Case 1
                chkMU1v1.Checked = True
            Case 2
                chkMU2v2.Checked = True
        End Select

        Select Case My.Settings.iconType
            Case 1
                chkRaceIcon.Checked = True
            Case 2
                chkRaceUnit.Checked = True
        End Select

        Select Case My.Settings.locHotkeyMode
            Case 1
                chkLocClock.Checked = True
            Case 2
                chkLocNumber.Checked = True
        End Select

        chkScoreIncrease.Checked = My.Settings.scoreClick
        chkTextFade.Checked = My.Settings.textFade
        chkLocEnabled.Checked = My.Settings.locEnabled
        chkMovable.Checked = StreamerMatch.moveEnabled


    End Sub

    Private Sub hidecontrols(Optional ByVal partialPanel As Boolean = False, Optional ByVal full As Boolean = False)
        If partialPanel Then
            For Each c As Control In pnlPreview.Controls
                c.Visible = False
            Next
        End If
        If full Then
            For Each c As Control In pnlPreviewFull.Controls
                c.Visible = False
            Next
        End If
    End Sub

    Private Sub updatePreviewFull() Handles chkScoreFixed.CheckedChanged, chkScoreIndividual.CheckedChanged, chkLocClock.CheckedChanged, chkLocNumber.CheckedChanged, chkMU1v1.CheckedChanged, chkMU2v2.CheckedChanged, chkRaceIcon.CheckedChanged, chkRaceUnit.CheckedChanged, chkLocEnabled.CheckedChanged, chkclrName.CheckedChanged, chkclrSquare.CheckedChanged
        If chkMU1v1.Checked Then
            '1v1
            tblPreview1v1.Visible = True
            tblPreview2v2.Visible = False
            If chkclrName.Checked = True Then
                Label16.ForeColor = Color.Red
                Label20.ForeColor = Color.DodgerBlue
                Button29.Visible = False
                Button30.Visible = False
            ElseIf chkclrSquare.Checked Then
                Label16.ForeColor = lblScoreOnelbl1v1.ForeColor
                Label20.ForeColor = lblScoreOnelbl1v1.ForeColor
                Button29.Visible = True
                Button30.Visible = True
                Button29.BackColor = Color.Red
                Button30.BackColor = Color.DodgerBlue
            End If

            If chkScoreIndividual.Checked Then
                TableLayoutPanel4.Visible = False
                lblScoreOnelbl1v1.Visible = True
            ElseIf chkScoreFixed.Checked Then
                TableLayoutPanel4.Visible = True
                lblScoreOnelbl1v1.Visible = False
            End If

            If chkRaceIcon.Checked Then
                Button27.BackgroundImage = imgIcon.Images(0)
                Button33.BackgroundImage = imgIcon.Images(1)
            ElseIf chkRaceUnit.Checked Then
                Button27.BackgroundImage = imgUnit.Images(0)
                Dim tempimg As Bitmap = imgUnit.Images(1)
                tempimg.RotateFlip(RotateFlipType.RotateNoneFlipX)
                Button33.BackgroundImage = tempimg
            End If

            If chkLocEnabled.Checked Then
                Label22.Visible = True
                Label23.Visible = True
            Else
                Label22.Visible = False
                Label23.Visible = False
            End If

        ElseIf chkMU2v2.Checked Then
            '2v2
            hidecontrols(True, True)
            tblPreview1v1.Visible = False
            tblPreview2v2.Visible = True
            If chkclrName.Checked = True Then
                lblplr1.ForeColor = Color.Red
                lblplr2.ForeColor = Color.DodgerBlue
                lblplr3.ForeColor = Color.Purple
                lblplr4.ForeColor = Color.Orange
                btnplrcolor1.Visible = False
                btnplrcolor2.Visible = False
                btnplrcolor3.Visible = False
                btnplrcolor4.Visible = False
            ElseIf chkclrSquare.Checked Then
                lblplr1.ForeColor = lblScoreOnelbl1v1.ForeColor
                lblplr2.ForeColor = lblScoreOnelbl1v1.ForeColor
                lblplr3.ForeColor = lblScoreOnelbl1v1.ForeColor
                lblplr4.ForeColor = lblScoreOnelbl1v1.ForeColor
                btnplrcolor1.Visible = True
                btnplrcolor2.Visible = True
                btnplrcolor3.Visible = True
                btnplrcolor4.Visible = True
                btnplrcolor1.BackColor = Color.Red
                btnplrcolor2.BackColor = Color.DodgerBlue
                btnplrcolor3.BackColor = Color.Purple
                btnplrcolor4.BackColor = Color.Orange
            End If

            If chkScoreIndividual.Checked Then
                TableLayoutPanel3.Visible = False
                lblScoreOnelbl2v2.Visible = True
            ElseIf chkScoreFixed.Checked Then
                TableLayoutPanel3.Visible = True
                lblScoreOnelbl2v2.Visible = False
            End If

            If chkRaceIcon.Checked Then
                Button10.BackgroundImage = imgIcon.Images(0)
                Button11.BackgroundImage = imgIcon.Images(1)
                Button12.BackgroundImage = imgIcon.Images(2)
                Button13.BackgroundImage = imgIcon.Images(3)
            ElseIf chkRaceUnit.Checked Then
                Button10.BackgroundImage = imgUnit.Images(0)
                Button11.BackgroundImage = imgUnit.Images(1)
                Dim tempimg As Bitmap = imgUnit.Images(2)
                tempimg.RotateFlip(RotateFlipType.RotateNoneFlipX)
                Button12.BackgroundImage = tempimg
                tempimg = imgUnit.Images(3)
                tempimg.RotateFlip(RotateFlipType.RotateNoneFlipX)
                Button13.BackgroundImage = tempimg
            End If

            If chkLocEnabled.Checked Then
                lblplr1loc.Visible = True
                lblplr2loc.Visible = True
                lblplr3loc.Visible = True
                lblplr4loc.Visible = True
            Else
                lblplr1loc.Visible = False
                lblplr2loc.Visible = False
                lblplr3loc.Visible = False
                lblplr4loc.Visible = False
            End If
        End If

    End Sub

    Private Sub chkRaceIcon_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkRaceIcon.MouseEnter
        hidecontrols(True)
        tbltblPreviewRaceIcons.Visible = True
    End Sub

    Private Sub all_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkRaceIcon.MouseLeave, chkRaceUnit.MouseLeave, chkScoreFixed.MouseLeave, chkScoreIndividual.MouseLeave, chkLocEnabled.MouseLeave, chkclrSquare.MouseLeave, chkclrName.MouseLeave
        hidecontrols(True)
    End Sub

    Private Sub chkRaceUnit_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkRaceUnit.MouseEnter
        hidecontrols(True)
        tblPreviewRaceUnits.Visible = True
    End Sub

    Private Sub chkColorName_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkclrName.MouseEnter
        hidecontrols(True)
        lblPreviewColorName.Visible = True
    End Sub

    Private Sub chkColorSquare_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkclrSquare.MouseEnter
        hidecontrols(True)
        tblPreviewColorSquare.Visible = True
    End Sub

    Private Sub btnEditPlayers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditPlayers.Click
        Dim f As New editPlayers
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
        End If
    End Sub

    Private Sub saveSettings()
        If chkclrName.Checked Then
            My.Settings.colorType = 1
        Else
            My.Settings.colorType = 2
        End If

        If chkScoreFixed.Checked Then
            My.Settings.scoreMode = 1
        Else
            My.Settings.scoreMode = 2
        End If

        If chkMU1v1.Checked Then
            My.Settings.matchUp = 1
        Else
            My.Settings.matchUp = 2
        End If

        If chkRaceIcon.Checked Then
            My.Settings.iconType = 2
        Else
            My.Settings.iconType = 1
        End If

        If chkLocClock.Checked Then
            My.Settings.locHotkeyMode = 1
        Else
            My.Settings.locHotkeyMode = 2
        End If

        StreamerMatch.moveEnabled = chkMovable.Checked
        My.Settings.locEnabled = chkLocEnabled.Checked
        My.Settings.scoreClick = chkScoreIncrease.Checked
        My.Settings.textFade = chkTextFade.Checked
    End Sub

    Private Sub btnResetPos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResetPos.Click
        StreamerMatch.Location = New Point(((Screen.PrimaryScreen.Bounds.Width - 693) / 2), 1)
        StreamerMatch.Refresh()
    End Sub

    Private Sub chkScoreFixed_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkScoreFixed.MouseEnter
        hidecontrols(True)
        lblPreviewScoreFixed.Visible = True
    End Sub

    Private Sub chkScoreIndividual_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkScoreIndividual.MouseEnter
        hidecontrols(True)
        lblPreviewScoreIndividual.Visible = True
    End Sub
End Class
